module WWW
  class Ali
    class Taobao
      class Trade<WWW::Ali::Util::Api
        attr_reader :fields,:start_created,:page_no,:page_size,:title,:status,:end_created

        def initialize(request,session)
          super(request,session)
          @fields=request[:fields]
          @start_created=request[:start_created]
          @page_no=request[:page_no]
          @page_size=request[:page_size]
          @title=request[:title]
          @status=request[:status]
          @end_created=request[:end_created]
        end
        #搜索当前会话用户做为买家达成的交易记录
        def get_buy_items
          params = get_buy_items_params
          return WWW::Ali::Util::Tool::get_result params
        end
        def get_buy_items_params
          ret_val = get_params
          ##系统级别参数
          ret_val['sip_apiname']="taobao.trades.bought.get"
          ##应用级别参数
          ret_val['fields']=@fields

          ret_val['start_created']=@start_created unless @start_created==nil
          ret_val['page_no']=@page_no unless @page_no==nil
          ret_val['page_size']=@page_size unless @page_size==nil

          ret_val['title']=@title unless @title==nil
          ret_val['status']=@status unless @status==nil
          ret_val['end_created']=@end_created unless @end_created==nil

          ret_val['format']='xml'
          ret_val['v']=1.0

          ##计算获得签名信息
          ret_val['sip_sign']=WWW::Ali::Util::Tool::get_sip_sign ret_val

          return ret_val
        end
        #搜索当前会话用户做为卖家达成的交易记录
        def get_sell_items
          params = get_sell_items_params
          return WWW::Ali::Util::Tool::get_result params
        end
        def get_sell_items_params
          ret_val = get_params
          ##系统级别参数
          ret_val['sip_apiname']="taobao.trades.sold.get"
          ##应用级别参数
          ret_val['fields']=@fields

          ret_val['start_created']=@start_created unless @start_created==nil
          ret_val['page_no']=@page_no unless @page_no==nil
          ret_val['page_size']=@page_size unless @page_size==nil

          ret_val['title']=@title unless @title==nil
          ret_val['status']=@status unless @status==nil
          ret_val['end_created']=@end_created unless @end_created==nil

          ret_val['format']='xml'
          ret_val['v']=1.0

          ##计算获得签名信息
          ret_val['sip_sign']=WWW::Ali::Util::Tool::get_sip_sign ret_val

          return ret_val
        end
      end
    end
  end
end
